package com.qf.eduadmin.controller;

import com.qf.eduadmin.pojo.req.TbPermissionReq;
import com.qf.eduadmin.pojo.resp.ResponseData;
import com.qf.eduadmin.pojo.vo.TbPermission;
import com.qf.eduadmin.service.TbPermissionService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TbPermission)表控制层
 *
 * @author makejava
 * @since 2021-12-27 21:01:41
 */
@RestController
@RequestMapping("/permission")
public class TbPermissionController {
    @Resource
    private TbPermissionService tbPermissionService;

    @RequestMapping("/findAll")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/findAll"})
    public ResponseData findAll(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit){
        ResponseData responseData = tbPermissionService.queryAllByLimit(page, limit);
        return responseData;
    }

    @RequestMapping("/insertPer")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/insertPer"})
    public ResponseData insertPer(@RequestBody TbPermissionReq tbPermissionReq){
        ResponseData responseData = tbPermissionService.insert(tbPermissionReq);
        return responseData;
    }

    @RequestMapping("/deletePer")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/deletePer"})
    public ResponseData deletePer(@RequestParam("permissionid")Integer permissionid){
        ResponseData responseData = tbPermissionService.deleteById(permissionid);
        return responseData;
    }

    @RequestMapping("/queryById")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/queryById"})
    public ResponseData queryById(@RequestParam("permissionid")Integer permissionid){
        ResponseData responseData = tbPermissionService.queryById(permissionid);
        return responseData;
    }

    @RequestMapping("/updatePer")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/updatePer"})
    public ResponseData updatePer(@RequestBody TbPermission tbPermission){
        ResponseData responseData = tbPermissionService.update(tbPermission);
        return responseData;
    }

    @RequestMapping("/findPermissionByRoleId")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/permission/findPermissionByRoleId"})
    public ResponseData findPermissionByRoleId(@RequestParam("id")Integer roleId){
        ResponseData responseData = tbPermissionService.findPermissionByRoleId(roleId);
        return responseData;
    }
}